Several changes to upgrade process on both server and client side.
authorrobertl <robertl>
Sun, 9 Aug 2009 03:09:11 +0000 (03:09 +0000)
committerrobertl <robertl>
Sun, 9 Aug 2009 03:09:11 +0000 (03:09 +0000)
Include "details..." dialog so a user can get a preview of the needed upgrade
and pop open a desktop browser so they can actually do the download.

gui/upgrade.cpp
gui/upgrade.h

index 6cb26795a6735f47619ab8fb2219903da33de7b4..5a89e2f13e3760203dab9322b6e613be4a9d1fc5 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: upgrade.cpp,v 1.6 2009/08/07 00:25:43 robertl Exp $
+// $Id: upgrade.cpp,v 1.7 2009/08/09 03:09:11 robertl Exp $
 /*
     Copyright (C) 2009  Robert Lipe, robertlipe@gpsbabel.org
 
 
 #include <QHttp>
 #include <QMessageBox>
+#include <QDesktopServices>
 #include <QDomDocument>
 #include <QSysInfo>
+#include <QUrl>
 
 // static const bool testing = true;
 static const bool testing = false;
 
-static int versionAsNumber(const QString &s) 
-{
-  QStringList list = s.split(".");
-  return (list[0].toInt()<<16 | list[1].toInt() << 8 | list[2].toInt() );
-}
-
 UpgradeCheck::UpgradeCheck(QWidget *parent) :
   QObject(parent),
   http(0)
@@ -52,28 +48,60 @@ UpgradeCheck::~UpgradeCheck()
   }
 }
 
-// See http://doc.trolltech.com/4.5/qsysinfo.html to interpret results
 QString UpgradeCheck::UpgradeCheck::getOsName(void)
 {
-       // Do not translate these strings.
+  // Do not translate these strings.
 #if defined (Q_OS_LINUX)
-               return "Linux";
+    return "Linux";
 #elif defined (Q_OS_MAC)
-       return QString("Mac %1").arg(QSysInfo::MacintoshVersion);
+  return "Mac";
 #elif defined (Q_OS_WIN)
-       return QString("Windows %1").arg(QSysInfo::WindowsVersion);
+  return "Windows";
 #elif
-       return "Unknown"'
+  return "Unknown"'
 #endif
-       
+  
 }
 
-UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentVersion,
-                                                        int checkMethod,
-                                                        const QDateTime &lastCheckTime,
-                                                        const QString &installationUuid)
+// See http://doc.trolltech.com/4.5/qsysinfo.html to interpret results  
+QString UpgradeCheck::UpgradeCheck::getOsVersion(void)
 {
-  this->currentVersion = currentVersion;
+  #if defined (Q_OS_MAC)
+  switch (QSysInfo::MacintoshVersion) {
+  case QSysInfo::MV_10_3: return "10.3"; break;
+  case QSysInfo::MV_10_4: return "10.4"; break;
+  case QSysInfo::MV_10_5: return "10.5"; break;
+  case QSysInfo::MV_10_6: return "10.6"; break;
+  default: return QString("Unknown Mac %1").arg(QSysInfo::MacintoshVersion);
+  };
+  #elif defined (Q_OS_WIN)
+  switch (QSysInfo::WinVersion) {
+  // Wildly improbable...
+  case QSysInfo::WV_95: return "95"; break;
+  case QSysInfo::WV_98: return "98"; break;
+  case QSysInfo::WV_Me: return "Me"; break;
+
+  case QSysInfo::WV_4_0: return "NT 4"; break;
+  case QSysInfo::WV_5_0: return "2000"; break;
+  case QSysInfo::WV_5_1: return "XP"; break;
+  case QSysInfo::WV_5_2: return "2003"; break;
+  case QSysInfo::WV_6_0: return "Vista"; break;
+  case QSysInfo::WV_6_1: return "7"; break;
+
+  }
+  #endif
+  // FIXME: find something appropriately clever to do for Linux, etc. here.
+  return "Unknown";  
+}
+  
+
+UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentVersionIn,
+               int checkMethod,
+               const QDateTime &lastCheckTime,
+               const QString &installationUuid)
+{
+  this->currentVersion = currentVersionIn;
+  this->currentVersion.remove("GPSBabel Version");
   this->upgradeCheckMethod = checkMethod;
 
   QDateTime soonestCheckTime = lastCheckTime.addDays(1);
@@ -81,7 +109,7 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
     // Not time to check yet.
     return UpgradeCheck::updateUnknown;
   }
-       
+  
   http = new QHttp;
   
   connect(http, SIGNAL(requestFinished(int, bool)),
@@ -95,11 +123,13 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
   header.setValue("Host", "www.gpsbabel.org");
 
   QString args = "current_version=" + currentVersion;
-  args += "&installation=" + installationUuid; 
-       args += "&os=" + getOsName();   
+  args += "&installation=" + installationUuid;  
+  args += "&os=" + getOsName();  
+  args += "&os_ver=" + getOsVersion();
+  args += "&beta_ok=1";   // Eventually to come from prefs.
 
   http->setHost("www.gpsbabel.org");
-       httpRequestId = http->request(header, args.toUtf8());
+  httpRequestId = http->request(header, args.toUtf8());
 
   return UpgradeCheck::updateUnknown;
 }
@@ -117,8 +147,8 @@ void UpgradeCheck::readResponseHeader(const QHttpResponseHeader &responseHeader)
     
   default:
     QMessageBox::information(0, tr("HTTP"),
-                            tr("Download failed: %1.")
-                            .arg(responseHeader.reasonPhrase()));
+           tr("Download failed: %1.")
+           .arg(responseHeader.reasonPhrase()));
     httpRequestAborted = true;
     http->abort();
   }
@@ -139,14 +169,13 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error)
     return;
   
   QString response;
+  QString upgradeText;
   
   if (testing)
     currentVersion =  "1.3.1"; // for testing
 
   bool allowBeta = false;  // TODO: come from prefs or current version...
 
-  int currentVersionNum = versionAsNumber(currentVersion);
-  
   QDomNodeList upgrades = document.elementsByTagName("update");
   
   for (unsigned int i = 0; i < upgrades.length(); i++) {
@@ -157,30 +186,39 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error)
     bool updateIsBeta  = upgrade.attribute("type") == "beta";
     bool updateIsMajor = upgrade.attribute("type") == "major";
     bool updateCandidate = updateIsMajor || (updateIsBeta && allowBeta);
-    int updateVersionNum = versionAsNumber(updateVersion);
-    
-    if(updateVersionNum > currentVersionNum && updateCandidate) {
-      response = tr("<center><b>A new version of GPSBabel is available</b><br>"
-                   "Your version is %1 <br>"
-                   "The latest version is %2</center>"
-                   "<center><a ref=\"http://www.gpsbabel.org/download.html\">"
-                   "Download GPSBabel</a> now.</center>")
-               .arg(currentVersion)
-               .arg(updateVersion);
-
+    upgradeText = upgrade.firstChildElement("overview").text();
+  
+    // String compare, not a numeric one.  Server will return "best first".
+    if((updateVersion > currentVersion) && updateCandidate) {
+      response = tr("A new version of GPSBabel is available.<br />"
+        "Your version is %1 <br />"
+        "The latest version is %2")
+          .arg(currentVersion)
+          .arg(updateVersion);
       break;  
     }
   }
-       
+  
   if (response.length()) {
     QMessageBox information;
     information.setWindowTitle(tr("Upgrade"));
-    information.setTextFormat(Qt::RichText);
+
+    information.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+    information.setDefaultButton(QMessageBox::Yes);
+  
     information.setText(response);
-    information.exec();
+    information.setInformativeText(tr("Do you wish do download an upgrade?"));
+    information.setDetailedText(upgradeText);
+  
+    switch (information.exec()) {
+      case QMessageBox::Yes: 
+          QDesktopServices::openUrl(QUrl("http://www.gpsbabel.org/download.html", QUrl::TolerantMode));
+      default: ;
+    }
+  
     upgradeWarningTime = QDateTime(QDateTime::currentDateTime());
   }
-       
+  
   delete http;
   http = 0;
 }
index 89753d79402876f5b2d663de8c61466904ede7af..cbb5fcd3c97db3c6b696b8a633b899e4a485bcd9 100644 (file)
@@ -58,6 +58,8 @@ protected:
   QString latestVersion;
   QDateTime upgradeWarningTime;  // invalid time if this object never issued.
   QString getOsName(void);
+  QString getOsVersion(void);
+
 
 private slots:
   void httpRequestFinished(int requestId, bool error);